package cn.gok.springsecuritydemo01.authenticationHandler;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**

 * @description:  自定义的退出登录成功以后 的处理逻辑
 */
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {

    /**
     * 自定义退出登录的逻辑
     */
    @Override
    public void onLogoutSuccess(HttpServletRequest request,
                                HttpServletResponse response,
                                Authentication authentication) throws IOException, ServletException {
        Enumeration<String> names = request.getSession().getAttributeNames();
        while (names.hasMoreElements()) {
            String element = names.nextElement();
            System.out.println(element);
        }
        //跳转回登录页面
        response.sendRedirect("/toLoginPage");

    }
}
